package com.example.yuntiku.Service;

import com.example.yuntiku.dao.impl.CurriculumDaoImpl;
import com.example.yuntiku.entity.Curriculum;

import java.util.List;

public class CurriculumService {
    CurriculumDaoImpl curriculumDao = new CurriculumDaoImpl();
    public CurriculumService() {
        this.curriculumDao = new CurriculumDaoImpl();
    }

    public List<Curriculum> getCurriculums() {
        List<Curriculum> topLevelCourses = curriculumDao.selectAll();
        for (Curriculum curriculum : topLevelCourses) {
            setChildCourses(curriculum);
        }
        return topLevelCourses;
    }
    public List<Curriculum> two(int selectedOne) {
        List<Curriculum> topLevelCourses = curriculumDao.selectByFknowledge(selectedOne);
        for (Curriculum curriculum : topLevelCourses) {
            setChildCourses(curriculum);
        }
        return topLevelCourses;
    }

    private void setChildCourses(Curriculum parentCurriculum) {
        List<Curriculum> childCourses = curriculumDao.selectZji(parentCurriculum.getCid());
        parentCurriculum.setChildren(childCourses);
        for (Curriculum childCurriculum : childCourses) {
            setChildCourses(childCurriculum);
        }
    }
    public List<Curriculum> selecterjilei(){
        return curriculumDao.selecterjilei();
    }
    public Curriculum selectName(int cid) {
        return curriculumDao.selectName(cid);
    }

    public List<Curriculum> selectAll(){
        return curriculumDao.selectAll();
    }
    public List<Curriculum> selectZji(int fknowledge){
        return curriculumDao.selectZji(fknowledge);
    }

    public List<Curriculum> selectAll2(){return curriculumDao.selectAll2();}

}

